import dotenv

from langchain_community.chat_models.baidu_qianfan_endpoint import QianfanChatEndpoint
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI

dotenv.load_dotenv()

# 1. 构建prompt与LLM，并将model切换为kemi
prompt = ChatPromptTemplate.from_template("{query}")

# 2. llm模型
llm = ChatOpenAI(model="kimi-k2-0711-preview-》〉》〉111").with_fallbacks(
    [QianfanChatEndpoint()]
)

# 3. 构建链应用
chain = prompt | llm | StrOutputParser()

# 4.调用链并输出结果
content = chain.invoke({"query": "你好，你是谁？"})

print(content)



